//
//  MRCityNewDiscount_TableViewCell.m
//  Travel_World
//
//  Created by dllo on 15/10/16.
//  Copyright © 2015年 TLS. All rights reserved.
//

#import "MRCityNewDiscount_TableViewCell.h"
#import "MRCountry_DiscountTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "MRCountry_DiscountModel.h"


@implementation MRCityNewDiscount_TableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self createTableView];
        
    }
    return self;
}

- (void)createTableView
{
    self.tableView = [[UITableView alloc] init];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    [self.contentView addSubview:self.tableView];
    
    self.tableView.bounces = NO;
    
    self.tableView.rowHeight = 90 * HEI;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.arr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.arr.count > indexPath.row) {
        static NSString *reuse = @"reuse";
        MRCountry_DiscountTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuse];
        if (!cell) {
            
            cell = [[MRCountry_DiscountTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuse];
            
        }
        
        MRCountry_DiscountModel *model = self.arr[indexPath.row];
        
        [cell.ImageView sd_setImageWithURL:[NSURL URLWithString:model.photo]placeholderImage:[UIImage imageNamed:@"placeholder1"]];
        cell.title.text = model.title;
        
        NSString *priceStr = model.price;
        NSString *price = [priceStr substringWithRange:NSMakeRange(4, priceStr.length-11)];
        cell.price.text = [NSString stringWithFormat:@"%@元起",price];
        
//        cell.price.text = model.price;
        cell.discount.text = model.priceoff;
        
//        [self.tableView reloadData];
        
        return cell;
    }
    return nil;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"fdsafdsa");
    
    NSDictionary *dic = @{@"index":[self.arr[indexPath.row] Id]};
    [[NSNotificationCenter defaultCenter] postNotificationName:@"tableViewClick" object:nil userInfo:dic];
    
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.tableView.frame = CGRectMake(0, 0, self.contentView.frame.size.width, self.arr.count * 90 * HEI);
    

    
//    NSLog(@"jfdiosfjidesjfiods++++______+_+_+_+_+_+_+%@",self.arr);
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
